class Question < ActiveRecord::Base
	include AliasingColumns
        
	set_table_name "QUESTIONS"  
	AliasingColumns.add_aliases columns
		
	belongs_to :survey,
			   :class_name => "Survey",
			   :foreign_key => "survey_id"
	belongs_to :questiontype,
			   :class_name => "QuestionType",
			   :foreign_key => "type_id"
			  		
			   
	has_one  :closedquestion, 			
			 :class_name => "ClosedQuestion",
 			 :foreign_key => "question_id",  
 			 :dependent => :destroy
 			 
 	has_many :answer,					#jezelio to jest openquestion - chyba do wywalenia
			 :class_name => "OQAnswer"	,	 
 			 :foreign_key => "question_id",   
 			 :dependent => :destroy
 	
	accepts_nested_attributes_for :closedquestion, :allow_destroy => true
	accepts_nested_attributes_for :answer, :allow_destroy => true
	validates_presence_of :question
	

	if  AliasingColumns.get_adapter_name == "oracle"
	#	self.primary_key ="ID"	
		set_sequence_name table_name()<<"_SEQ" 
	#	before_validation :set_id
		def set_id
			 self.ID =connection.next_sequence_value(self.class.sequence_name)	
		end 
	end


end
